package com.fsm.demo.controller;

import com.fsm.common.easyexcel.dto.TSRoleVo;
import com.fsm.common.tools.Result.Result;
import com.fsm.demo.service.EasyExcelService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 *  表格测试控制层。
 *
 * @author 翻山鸣
 * @since
 */
@RestController
@Tag(name = "表格测试")
@RequestMapping("/easyExcel")
public class EasyExcelController {

    @Autowired
    private EasyExcelService easyExcelService;

    /**
     * 配置表格信息
     *
     * @param tsRoleVo
     * @return
     */
    @PostMapping("configurationExcel")
    @Operation(summary="配置表格信息",description="配置表格信息")
    public Result configurationExcel(@RequestBody TSRoleVo tsRoleVo, HttpServletResponse response) throws Exception{
        return easyExcelService.configurationExcel(tsRoleVo,response);
    }

    /**
     * 最简单的写
     *
     * @param response
     * @return
     */
    @PostMapping("demo1Excel")
    @Operation(summary="最简单的写",description="最简单的写")
    public Result demo1Excel(HttpServletResponse response) throws Exception{
        return easyExcelService.demo1Excel(response);
    }

    /**
     * 排除/指定模型中的属性字段
     *
     * @param response
     * @return
     */
    @PostMapping("demo2Excel")
    @Operation(summary="排除/指定模型中的属性字段",description="排除/指定模型中的属性字段")
    public Result demo2Excel(HttpServletResponse response) throws Exception{
        return easyExcelService.demo2Excel(response);
    }

    /**
     * 插入指定的列
     *
     * @param response
     * @return
     */
    @PostMapping("demo3Excel")
    @Operation(summary="插入指定的列",description="插入指定的列")
    public Result demo3Excel(HttpServletResponse response) throws Exception{
        return easyExcelService.demo3Excel(response);
    }

    /**
     * 复杂头数据写入
     *
     * @param response
     * @return
     */
    @PostMapping("demo4Excel")
    @Operation(summary="复杂头数据写入",description="复杂头数据写入")
    public Result demo4Excel(HttpServletResponse response) throws Exception{
        return easyExcelService.demo4Excel(response);
    }

    /**
     * 日期/数字类型格式化
     *
     * @param response
     * @return
     */
    @PostMapping("demo6Excel")
    @Operation(summary="日期/数字类型格式化",description="日期/数字类型格式化")
    public Result demo6Excel(HttpServletResponse response) throws Exception{
        return easyExcelService.demo6Excel(response);
    }

    /**
     * 写入图片到Excel
     *
     * @param response
     * @return
     */
    @PostMapping("demo7Excel")
    @Operation(summary="写入图片到Excel",description="写入图片到Excel")
    public Result demo7Excel(HttpServletResponse response) throws Exception{
        return easyExcelService.demo7Excel(response);
    }

    /**
     * 通过注解形式设置写入Excel样式
     *
     * @param response
     * @return
     */
    @PostMapping("demo8Excel")
    @Operation(summary="通过注解形式设置写入Excel样式",description="通过注解形式设置写入Excel样式")
    public Result demo8Excel(HttpServletResponse response) throws Exception{
        return easyExcelService.demo8Excel(response);
    }

    /**
     * 合并单元格
     *
     * @param response
     * @return
     */
    @PostMapping("demo9Excel")
    @Operation(summary="合并单元格",description="合并单元格")
    public Result demo9Excel(HttpServletResponse response) throws Exception{
        return easyExcelService.demo9Excel(response);
    }

    /**
     * 自定义转换器
     *
     * @param response
     * @return
     */
    @PostMapping("demo10Excel")
    @Operation(summary="自定义转换器",description="自定义转换器")
    public Result demo10Excel(HttpServletResponse response) throws Exception{
        return easyExcelService.demo10Excel(response);
    }

    /**
     * 导入转换成List<List<String>>
     *
     * @param request
     * @return
     */
    @PostMapping("demo11Excel")
    @Operation(summary="导入转换成List<List<String>>",description="导入转换成List<List<String>>")
    public Result demo11Excel(HttpServletRequest request) throws Exception{
        return easyExcelService.demo11Excel(request);
    }

}
